﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Excel = Microsoft.Office.Interop.Excel;
using ThreeByte.ActiveDeck.Data.UserResponse;


namespace ThreeByte.ActiveDeck.Controls.UserResponse
{
    /// <summary>
    /// Interaction logic for QuestionResponseConfiguration.xaml
    /// </summary>
    public partial class QuestionResponseConfiguration : UserControl, IUserResponseConfigurationControl
    {

        private QuestionConfig mConfig;

        public QuestionResponseConfiguration(PageConfig config) {
            InitializeComponent();

            DataContext = config;
            mConfig = (QuestionConfig)config;

            DisplayTypeComboBox.SelectionChanged +=new SelectionChangedEventHandler(DisplayTypeComboBox_SelectionChanged);
            RefreshOptions();
        }

        public PowerPoint.Shape InsertUserResponseComponent(PowerPoint.Slide slide) {

            //TODO: Insert centered, at half the height/width of the slide
            float height = slide.Master.Height / 2.0f;
            float width = slide.Master.Width / 2.0f;

            PowerPoint.Shape theShape = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, width / 2.0f, height / 2.0f, width, height);
            //Store Section/Page info to the shape
            theShape.Name = @"ActiveDeck_Text";
            theShape.TextFrame2.AutoSize = Microsoft.Office.Core.MsoAutoSize.msoAutoSizeTextToFitShape;

            theShape.Tags.Add("Section", mConfig.ParentSlideConfig.SlideId.ToString());
            theShape.Tags.Add("Page", mConfig.PageId.ToString());
            theShape.Tags.Add("ConfigType", typeof(QuestionConfig).ToString());
            theShape.Tags.Add("Mode", (string)(DisplayTypeComboBox.SelectedValue));
            theShape.Tags.Add("ClickToAdvance", string.Format("{0}", ClickToAdvanceCheckBox.IsChecked ?? false));

            if(PreviewDataCheckBox.IsChecked ?? false) {
                theShape.TextFrame.TextRange.Text = "ActiveDeck User text shows up here";
            } else {
                theShape.TextFrame.TextRange.Text = " ";
            }
            //TODO: Consider the autoFit option.....
           
            return theShape;
        }

        private void DisplayTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            RefreshOptions();
        }

        private void RefreshOptions() {
            if(DisplayTypeComboBox.SelectedIndex == 1) {
                //Not a valid option
                ClickToAdvanceCheckBox.IsEnabled = false;
                ClickToAdvanceCheckBox.IsChecked = false;
            } else {
                ClickToAdvanceCheckBox.IsEnabled = true;
            }
        }

    }

    public class TextDisplayMode
    {
        public string Mode { get; set; }
        public string DisplayName { get; set; }
    }
}
